package com.omenkk.juc.AQS;

import com.omenkk.juc.util.Slepper;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Semaphore;
@Slf4j
public class SemaphoreDemo {

    public static void main(String[] args) {
        Semaphore semaphore=new Semaphore(1);
        new Thread(()->{
            try{
                semaphore.acquire();
                log.debug("运行中...三秒后运行完毕");
                Slepper.sleep(3);

            }catch (InterruptedException e){
                e.printStackTrace();
            }finally {
                semaphore.release();
            }
        }).start();
        new Thread(()->{
            try{
                semaphore.acquire();
                log.debug("运行中...三秒后运行完毕");
                Slepper.sleep(3);
            }catch (InterruptedException e){
                e.printStackTrace();
            }finally {
                semaphore.release();
            }
        }).start();
    }

}
